package flante;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: Flante EventListAdapter </p>
 * <p>Description: Creates a custom adapter to display List<events> </></p>
 * @author Aaron Cook, Mike Haas, Kyle Kolstad
 * @email aaron.cook@my.uwrf.edu, michael.haas.@my.uwrf.edu, kyle.kolstad@my.uwrf.edu
 * @date 12/4/2013
 */
public class EventListAdapter extends BaseAdapter {

    /**
     * EventListAdapter Class Data Members
     */
    private List<Event> eventList = new ArrayList<Event>();
    private LayoutInflater myInflater;

    /**
     * EventListAdapter default constructor
     * @param arrayList
     */
    public EventListAdapter(List<Event> arrayList, Context context){
        eventList = arrayList;
        myInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    /**
     * returns the size of the list
     * @return eventList.size()
     */
    @Override
    public int getCount() {
        return eventList.size();
    }

    /**
     * Returns object at the given location
     * @param i
     * @return eventList.get(i)
     */
    @Override
    public Object getItem(int i) {
        return eventList.get(i);
    }

    /**
     * returns item id
     * @param i
     * @return i
     */
    @Override
    public long getItemId(int i) {
        return  i;
    }

    /**
     *Creates a view with the simple_list_item_1 layout
     * and sets the textView with the a description from the
     * eventList
     * @param i
     * @param view
     * @param viewGroup
     * @return view
     * @see android.widget.BaseAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view==null)
            view = myInflater.inflate(android.R.layout.simple_list_item_1,viewGroup,false);
        TextView description = (TextView) view.findViewById(android.R.id.text1);
        String listItem = eventList.get(i).getDescription();
        description.setText(listItem);
        return view;
    }


}
